package com.lb.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.lb.dao.mysql.PersonMapper;
import com.lb.dao.mysql.entity.Person;

import cn.hutool.core.collection.ListUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * @author libin
 * @Date 2022/9/13 18:50
 * @since 1.0
 **/
@Service
@Slf4j
@AllArgsConstructor
public class PersonService {

    private final PersonMapper personMapper;

    @Cacheable(cacheNames = {"person"}, key = "#id")
    public Person cacheTest(Integer id) {

        Person person = personMapper.selectById(id);
        log.info("person:{}", JSON.toJSONString(person));
        return person;
    }

    public static void main(String[] args) {

        List<Integer> integers = new ArrayList<>();
        for (int i = 1; i <= 120; i++) {
            integers.add(i);
        }

        List<List<Integer>> lists = ListUtil.splitAvg(integers, 11);
        for (List<Integer> list : lists) {
            System.out.println(list.toString());
        }
    }

}
